home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / tos / othergnu / gnuchess.zoo / NONDSP.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-09  |  19.5 KB  |  809 lines

  1. /*
  2.   UNIX & MSDOS NON-DISPLAY, AND CHESSTOOL interface for Chess
  3.    
  4.   Revision: 4-25-88
  5.    
  6.   Copyright (C) 1986, 1987, 1988 Free Software Foundation, Inc.
  7.   Copyright (c) 1988  John Stanback
  8.  
  9.   This file is part of CHESS.
  10.  
  11.   CHESS is distributed in the hope that it will be useful,
  12.   but WITHOUT ANY WARRANTY.  No author or distributor
  13.   accepts responsibility to anyone for the consequences of using it
  14.   or for whether it serves any particular purpose or works at all,
  15.   unless he says so in writing.  Refer to the CHESS General Public
  16.   License for full details.
  17.  
  18.   Everyone is granted permission to copy, modify and redistribute
  19.   CHESS, but only under the conditions described in the
  20.   CHESS General Public License.   A copy of this license is
  21.   supposed to have been given to you along with CHESS so you
  22.   can know your rights and responsibilities.  It should be in a
  23.   file named COPYING.  Among other things, the copyright notice
  24.   and this notice must be preserved on all copies.
  25. */
  26.  
  27. /* modified by Eric R. Smith to compile under MEGAMAX Laser C
  28.     (I haven't actually tested it, though; I used the 'curses' version)
  29.    Aug 9, 1988
  30. */
  31.  
  32. #include <stdio.h>
  33. #include <ctype.h>
  34. #ifdef MSDOS
  35. # include <dos.h>
  36. # include <stdlib.h>
  37. # include <time.h>
  38. #else
  39. # ifdef MEGAMAX
  40. #  define MSDOS
  41.     extern long time();
  42. #  define W_OK 1
  43. # else 
  44. #  include <sys/param.h>
  45. #  include <sys/times.h>
  46. #  include <sys/file.h>
  47. #  include <signal.h>
  48.     struct tms tmbuf1,tmbuf2;
  49.     int TerminateSearch(),Die();
  50. # endif MEGAMAX
  51. #endif MSDOS
  52. #include "gnuchess.h"
  53.  
  54. #define printz printf
  55. #define scanz scanf
  56. int mycnt1,mycnt2;
  57.  
  58.  
  59. Initialize()
  60. {
  61.   mycnt1 = mycnt2 = 0;
  62. #ifndef MSDOS
  63.   signal(SIGINT,Die); signal(SIGQUIT,Die);
  64. #endif
  65. #ifdef CHESSTOOL
  66. /*
  67.   setlinebuf(stdout);
  68. */
  69.   setvbuf(stdout,NULL,_IOLBF,BUFSIZ);
  70.   printf("Chess\n");
  71.   if (Level == 0 && !TCflag) Level = 15;
  72. #endif CHESSTOOL
  73. }
  74.  
  75. ExitChess()
  76. {
  77.   ListGame();
  78.   exit(0);
  79. }
  80.  
  81. #ifndef MSDOS
  82. Die()
  83. {
  84. char s[80];
  85.   signal(SIGINT,SIG_IGN);
  86.   signal(SIGQUIT,SIG_IGN);
  87.   printz("Abort? ");
  88.   scanz("%s",s);
  89.   if (strcmp(s,"yes") == 0) ExitChess();
  90.   signal(SIGINT,Die); signal(SIGQUIT,Die);
  91. }
  92.  
  93. TerminateSearch()
  94. {
  95.   signal(SIGINT,SIG_IGN);
  96.   signal(SIGQUIT,SIG_IGN);
  97.   timeout = true;
  98.   bothsides = false;
  99.   signal(SIGINT,Die); signal(SIGQUIT,Die);
  100. }
  101. #endif MSDOS
  102.  
  103.  
  104. InputCommand()
  105.  
  106. /*
  107.    Process the users command. If easy mode is OFF (the computer is 
  108.    thinking on opponents time) and the program is out of book, then make 
  109.    the 'hint' move on the board and call SelectMove() to find a response. 
  110.    The user terminates the search by entering ^C (quit siqnal) before 
  111.    entering a command. If the opponent does not make the hint move, then 
  112.    set Sdepth to zero. 
  113. */
  114.  
  115. {
  116. int i;
  117. short ok,tmp;
  118. long cnt,rate,t1,t2;
  119. unsigned short mv;
  120. char s[80];
  121.  
  122.   ok = quit = false;
  123.   player = opponent;
  124.   ft = 0;
  125.   if (hint > 0 && !easy && Book == NULL)
  126.     {
  127.       fflush(stdout);
  128.       time0 = time((long *)0);
  129.       algbr(hint>>8,hint & 0xFF,false);
  130.       strcpy(s,mvstr1);
  131.       tmp = epsquare;
  132.       if (VerifyMove(s,1,&mv))
  133.         {
  134.           SelectMove(computer,2);
  135.           VerifyMove(mvstr1,2,&mv);
  136.           if (Sdepth > 0) Sdepth--;
  137.         }
  138.       ft = time((long *)0) - time0;
  139.       epsquare = tmp;
  140.     }
  141.   
  142. #ifndef MSDOS
  143.   signal(SIGINT,Die); signal(SIGQUIT,Die);
  144. #endif
  145.   while (!(ok || quit))
  146.     {
  147.       PromptForMove();
  148.       i = scanz("%s",s);
  149.       if (i == EOF || s[0] == 0) ExitChess();
  150.       player = opponent;
  151.       ok = VerifyMove(s,0,&mv);
  152.       if (ok && mv != hint)
  153.         {
  154.           Sdepth = 0;
  155.           ft = 0;
  156.         }
  157.         
  158.       if (strcmp(s,"bd") == 0)
  159.         {
  160.           ClrScreen();
  161.           UpdateDisplay(0,0,1,0);
  162.         }
  163.       if (strcmp(s,"quit") == 0) quit = true;
  164.       if (strcmp(s,"post") == 0) post = !post;
  165.       if (strcmp(s,"edit") == 0) EditBoard();
  166.       if (strcmp(s,"go") == 0) ok = true;
  167.       if (strcmp(s,"help") == 0) help();
  168.       if (strcmp(s,"force") == 0) force = !force;
  169.       if (strcmp(s,"book") == 0) Book = NULL;
  170.       if (strcmp(s,"new") == 0) NewGame();
  171.       if (strcmp(s,"list") == 0) ListGame();
  172.       if (strcmp(s,"level") == 0) SelectLevel();
  173.       if (strcmp(s,"hash") == 0) hashflag = !hashflag;
  174.       if (strcmp(s,"beep") == 0) beep = !beep;
  175.       if (strcmp(s,"Awindow") == 0) ChangeAlphaWindow();
  176.       if (strcmp(s,"Bwindow") == 0) ChangeBetaWindow();
  177.       if (strcmp(s,"rcptr") == 0) rcptr = !rcptr;
  178.       if (strcmp(s,"hint") == 0) GiveHint();
  179.       if (strcmp(s,"zero") == 0) ZeroTTable();
  180.       if (strcmp(s,"both") == 0)
  181.         {
  182.           bothsides = !bothsides;
  183.           Sdepth = 0;
  184.           SelectMove(opponent,1);
  185.           ok = true;
  186.         }
  187.       if (strcmp(s,"reverse") == 0)
  188.         {
  189.           reverse = !reverse;
  190.           ClrScreen();
  191.           UpdateDisplay(0,0,1,0);
  192.         }
  193.       if (strcmp(s,"switch") == 0)
  194.         {
  195.           computer = otherside[computer];
  196.           opponent = otherside[opponent];
  197.           force = false;
  198.           Sdepth = 0;
  199.           ok = true;
  200.         }
  201.       if (strcmp(s,"white") == 0)  
  202.         {
  203.           computer = white; opponent = black;
  204.           ok = true; force = false;
  205.           Sdepth = 0;
  206.         }
  207.       if (strcmp(s,"black") == 0)
  208.         {
  209.           computer = black; opponent = white;
  210.           ok = true; force = false;
  211.           Sdepth = 0;
  212.         }
  213.       if (strcmp(s,"undo") == 0 && GameCnt >= 0) Undo();
  214.       if (strcmp(s,"remove") == 0 && GameCnt >= 1) 
  215.         {
  216.           Undo(); Undo();
  217.         }
  218.       if (strcmp(s,"get") == 0) GetGame();
  219.       if (strcmp(s,"save") == 0) SaveGame();
  220.       if (strcmp(s,"depth") == 0) ChangeSearchDepth();
  221.       if (strcmp(s,"random") == 0) dither = 6;
  222.       if (strcmp(s,"easy") == 0) easy = !easy;
  223.       if (strcmp(s,"contempt") == 0) SetContempt();
  224.       if (strcmp(s,"xwndw") == 0) ChangeXwindow();
  225.       if (strcmp(s,"test") == 0)
  226.         {
  227.           t1 = time(0);
  228.           cnt = 0;
  229.           for (i = 0; i < 10000; i++)
  230.             {
  231.               MoveList(opponent,2);
  232.               cnt += TrPnt[3] - TrPnt[2];
  233.             }
  234.           t2 = time(0);
  235.           rate = cnt / (t2-t1);
  236.           printz("cnt= %ld  rate= %ld\n",cnt,rate);
  237.         }
  238.     }
  239.     
  240.   ElapsedTime(1);
  241.   if (force)
  242.     {
  243.       computer = opponent; opponent = otherside[computer];
  244.     }
  245. #ifndef MSDOS
  246.   (void) times(&tmbuf1);
  247. #ifdef CHESSTOOL
  248.   printf("%d. %s\n",++mycnt2,s);
  249. #endif CHESSTOOL
  250.   signal(SIGINT,TerminateSearch); signal(SIGQUIT,TerminateSearch);
  251. #endif MSDOS
  252. }
  253.  
  254.  
  255. help()
  256. {
  257.   ClrScreen();
  258.   printz("CHESS command summary\n");
  259.   printz("g1f3      move from g1 to f3\n");
  260.   printz("nf3       move knight to f3\n");
  261.   printz("o-o       castle king side\n");
  262.   printz("o-o-o     castle queen side\n");
  263.   printz("edit      edit board\n");
  264.   printz("switch    sides with computer\n");
  265.   printz("white     computer plays white\n");
  266.   printz("black     computer plays black\n");
  267.   printz("reverse   board display\n");
  268.   printz("both      computer match\n");
  269.   printz("random    randomize play\n");
  270.   printz("undo      undo last move\n");
  271.   printz("time      change level\n");
  272.   printz("depth     set search depth\n");
  273.   printz("post      principle variation\n");
  274.   printz("hint      suggest a move\n");
  275.   printz("bd        redraw board\n");
  276.   printz("clock     set time control\n");
  277.   printz("force     enter game moves\n");
  278.   printz("list      game to chess.lst\n");
  279.   printz("save      game to file\n");
  280.   printz("get       game from file\n");
  281.   printz("new       start new game\n");
  282.   printz("quit      exit CHESS\n");
  283.   printz("Computer: ");
  284.   if (computer == white) printz("WHITE\n"); else printz("BLACK\n");
  285.   printz("Opponent: ");
  286.   if (opponent == white) printz("WHITE\n"); else printz("BLACK\n");
  287.   printz("Response time: %ld \n",Level);
  288.   printz("Easy mode: ");
  289.   if (easy) printz("ON\n"); else printz("OFF\n");
  290.   printz("Depth: %d\n",MaxSearchDepth);
  291.   printz("Random: "); 
  292.   if (dither) printz("ON\n"); else printz("OFF\n");
  293.   printz("Transposition table: ");
  294.   if (hashflag) printz("ON\n"); else printz("OFF\n");
  295.   UpdateDisplay(0,0,1,0);
  296. }
  297.  
  298.  
  299. EditBoard()
  300.  
  301. /* 
  302.    Set up a board position. Pieces are entered by typing the piece 
  303.    followed by the location. For example, Nf3 will place a knight on 
  304.    square f3. 
  305. */
  306.  
  307. {
  308. short a,r,c,sq;
  309. char s[80];
  310.  
  311.   ClrScreen();
  312.   UpdateDisplay(0,0,1,0);
  313.   printz(".   exit to main\n");
  314.   printz("#   clear board\n");
  315.   printz("enter piece & location: \n");
  316.   
  317.   a = white;
  318.   do
  319.   {
  320.     scanz("%s",s);
  321.     if (s[0] == '#')
  322.       {
  323.         for (sq = 0; sq < 64; sq++)
  324.           {
  325.             board[sq] = no_piece; color[sq] = neutral;
  326.           }
  327.         UpdateDisplay(0,0,1,0);
  328.       }
  329.     if (s[0] == 'c' || s[0] == 'C') a = otherside[a];
  330.     c = s[1]-'a'; r = s[2]-'1';
  331.     if ((c >= 0) && (c < 8) && (r >= 0) && (r < 8))
  332.       {
  333.         sq = locn[r][c];
  334.         color[sq] = a;
  335.         if (s[0] == 'p') board[sq] = pawn;
  336.         else if (s[0] == 'n') board[sq] = knight;
  337.         else if (s[0] == 'b') board[sq] = bishop;
  338.         else if (s[0] == 'r') board[sq] = rook;
  339.         else if (s[0] == 'q') board[sq] = queen;
  340.         else if (s[0] == 'k') board[sq] = king;
  341.         else { board[sq] = no_piece; color[sq] = neutral; }
  342.       }
  343.   }
  344.   while (s[0] != '.');
  345.   if (board[4] != king) kingmoved[white] = 10;
  346.   if (board[60] != king) kingmoved[black] = 10;
  347.   GameCnt = -1; Game50 = 0; Sdepth = 0;
  348.   InitializeStats();
  349.   ClrScreen();
  350.   UpdateDisplay(0,0,1,0);
  351. }
  352.  
  353.  
  354. ShowDepth(ch)
  355. char ch;
  356. {
  357. }
  358.  
  359. ShowResults(score,bstline,ch)
  360. short score;
  361. unsigned short bstline[];
  362. char ch;
  363. {
  364. #ifndef CHESSTOOL
  365. register int i;
  366.   printz("%2d%c  %5d %4ld %7ld   ",Sdepth,ch,score,et,NodeCnt);
  367.   for (i = 1; bstline[i] > 0; i++)
  368.     {
  369.       algbr((short)(bstline[i] >> 8),(short)(bstline[i] & 0xFF),false);
  370.       if (i == 9 || i == 17) printz("\n                          ");
  371.       printz("%5s ",mvstr1);
  372.     }
  373.   printz("\n");
  374. #endif
  375. }
  376.  
  377.  
  378. SearchStartStuff(side)
  379. short side;
  380. {
  381. #ifndef MSDOS
  382.   signal(SIGINT,TerminateSearch); signal(SIGQUIT,TerminateSearch);
  383. #endif MSDOS
  384. #ifndef CHESSTOOL
  385.   printz("\nMove# %d    Target= %ld    Clock: %ld\n",
  386.           TCmoves-TimeControl.moves[side]+1,
  387.           ResponseTime,TimeControl.clock[side]);
  388. #endif
  389. }
  390.  
  391.  
  392. OutputMove()
  393. {
  394. #ifdef CHESSTOOL
  395.   printz("%d. ... %s\n",++mycnt1,mvstr1);
  396.   if (root->flags & draw)
  397.     {
  398.       printz("Draw\n");
  399.       ListGame();
  400.       exit(0);
  401.     }
  402.   if (root->score == -9999)
  403.     {
  404.       if (opponent == white) printz("White\n"); else printz("Black\n");
  405.       ListGame();
  406.       exit(0);
  407.     }
  408.   if (root->score == 9998)
  409.     {
  410.       if (computer == white) printz("White\n"); else printz("Black\n");
  411.       ListGame();
  412.       exit(0);
  413.     }
  414. #else
  415.   printz("Nodes= %ld  Eval= %ld  Hash= %ld  Rate= %ld  ",
  416.           NodeCnt,EvalNodes,HashCnt,evrate);
  417.   printz("CPU= %.2ld:%.2ld.%.2ld\n\n",
  418.           cputimer/6000,(cputimer % 6000)/100,cputimer % 100);
  419.           
  420.   if (root->flags & epmask) UpdateDisplay(0,0,1,0);
  421.   else UpdateDisplay(root->f,root->t,0,root->flags & cstlmask);
  422.   printz("My move is: %s\n\n",mvstr1);
  423.   if (beep) printz("%c",7);
  424.   
  425.   if (root->flags & draw) printz("Draw game!\n");
  426.   else if (root->score == -9999) printz("opponent mates!\n");
  427.   else if (root->score == 9998) printz("computer mates!\n");
  428.   else if (root->score < -9000) printz("opponent will soon mate!\n");
  429.   else if (root->score > 9000)  printz("computer will soon mate!\n");
  430. #endif CHESSTOOL
  431. }
  432.  
  433.  
  434. ElapsedTime(iop)
  435. short iop;
  436.  
  437. /* 
  438.    Determine the time that has passed since the search was started. If 
  439.    the elapsed time exceeds the target (ResponseTime+ExtraTime) then set 
  440.    timeout to true which will terminate the search. 
  441. */
  442.  
  443. {
  444.   et = time((long *)0) - time0;
  445.   if (et < 0) et = 0;
  446.   ETnodes += 50;
  447.   if (et > et0 || iop == 1)
  448.     {
  449.       if (et > ResponseTime+ExtraTime && Sdepth > 1) timeout = true;
  450.       et0 = et;
  451.       if (iop == 1)
  452.         {
  453.           time0 = time((long *)0); et0 = 0;
  454.         }
  455. #ifdef MSDOS
  456.       cputimer = 100*et;
  457.       if (et > 0) evrate = NodeCnt/(et+ft); else evrate = 0;
  458.       if (kbhit() && Sdepth > 1)
  459.         {
  460.           timeout = true;
  461.           bothsides = false;
  462.         }
  463. #else
  464.       (void) times(&tmbuf2);
  465.       cputimer = 100*(tmbuf2.tms_utime - tmbuf1.tms_utime) / HZ;
  466.       if (cputimer > 0) evrate = (100*NodeCnt)/(cputimer+100*ft);
  467.       else evrate = 0;
  468. #endif MSDOS
  469.       ETnodes = NodeCnt + 50;
  470.     }
  471. }
  472.  
  473.  
  474. SetTimeControl()
  475. {
  476.   if (TCflag)
  477.     {
  478.       TimeControl.moves[white] = TimeControl.moves[black] = TCmoves;
  479.       TimeControl.clock[white] = TimeControl.clock[black] = 60*(long)TCminutes;
  480.     }
  481.   else
  482.     {
  483.       TimeControl.moves[white] = TimeControl.moves[black] = 0;
  484.       TimeControl.clock[white] = TimeControl.clock[black] = 0;
  485.       Level = 60*(long)TCminutes;
  486.     }
  487.   et = 0;
  488.   ElapsedTime(1);
  489. }
  490.  
  491.  
  492. ClrScreen()
  493. {
  494. #ifndef CHESSTOOL
  495.   printz("\n");
  496. #endif
  497. }
  498.  
  499.  
  500. UpdateDisplay(f,t,flag,iscastle)
  501. short f,t,flag,iscastle;
  502. {
  503. #ifndef CHESSTOOL
  504. short r,c,l;
  505.   if (flag)
  506.     {
  507.       printz("\n");
  508.       for (r = 7; r >= 0; r--)
  509.         {
  510.           for (c = 0; c <= 7; c++)
  511.             {
  512.               if (reverse) l = locn[7-r][7-c]; else l = locn[r][c];
  513.               if (color[l] == neutral) printz(" -");
  514.               else if (color[l] == white) printz(" %c",qxx[board[l]]);
  515.               else printz(" %c",pxx[board[l]]);
  516.             }
  517.           printz("\n");
  518.         }
  519.       printz("\n");
  520.     }
  521. #endif CHESSTOOL
  522. }
  523.  
  524.  
  525. GetOpenings()
  526.  
  527. /*
  528.    Read in the Opening Book file and parse the algebraic notation for a 
  529.    move into an unsigned integer format indicating the from and to 
  530.    square. Create a linked list of opening lines of play, with 
  531.    entry->next pointing to the next line and entry->move pointing to a 
  532.    chunk of memory containing the moves. More Opening lines of up to 256 
  533.    half moves may be added to gnuchess.book. 
  534. */
  535.  
  536. {
  537. FILE *fd;
  538. int c,i,j,side;
  539. char buffr[2048];
  540. struct BookEntry *entry;
  541. unsigned short mv,*mp,tmp[100];
  542.  
  543.   if ((fd = fopen("gnuchess.book","r")) != NULL)
  544.     {
  545. #ifndef MEGAMAX
  546.       setvbuf(fd,buffr,_IOFBF,2048);
  547. #endif
  548.       Book = NULL;
  549.       i = 0; side = white;
  550.       while ((c = parse(fd,&mv,side)) >= 0)
  551.         if (c == 1)
  552.           {
  553.             tmp[++i] = mv;
  554.             side = otherside[side];
  555.           }
  556.         else if (c == 0 && i > 0)
  557.           {
  558.             entry = (struct BookEntry *)malloc(sizeof(struct BookEntry));
  559.             mp = (unsigned short *)malloc((i+1)*sizeof(unsigned short));
  560.             entry->mv = mp;
  561.             entry->next = Book;
  562.             Book = entry; 
  563.             for (j = 1; j <= i; j++) *(mp++) = tmp[j];
  564.             *mp = 0;
  565.             i = 0; side = white;
  566.           }
  567.       fclose(fd);
  568.     }
  569. }
  570.  
  571.  
  572. int parse(fd,mv,side)
  573. FILE *fd;
  574. unsigned short *mv;
  575. short side;
  576. {
  577. int c,i,r1,r2,c1,c2;
  578. char s[100];
  579.   while ((c = getc(fd)) == ' ');
  580.   i = 0; s[0] = c;
  581.   while (c != ' ' && c != '\n' && c != EOF) s[++i] = c = getc(fd);
  582.   s[++i] = '\0';
  583.   if (c == EOF) return(-1);
  584.   if (s[0] == '!' || i < 3)
  585.     {
  586.       while (c != '\n' && c != EOF) c = getc(fd);
  587.       return(0);
  588.     }
  589.   if (s[4] == 'o')
  590.     if (side == black) *mv = 0x3C3A; else *mv = 0x0402;
  591.   else if (s[0] == 'o')
  592.     if (side == black) *mv = 0x3C3E; else *mv = 0x0406;
  593.   else
  594.     {
  595.       c1 = s[0] - 'a'; r1 = s[1] - '1';
  596.       c2 = s[2] - 'a'; r2 = s[3] - '1';
  597.       *mv = (locn[r1][c1]<<8) + locn[r2][c2];
  598.     }
  599.   return(1);
  600. }
  601.  
  602.  
  603. GetGame()
  604. {
  605. FILE *fd;
  606. char fname[40];
  607. int c;
  608. short sq;
  609. unsigned short m;
  610.  
  611.   printz("Enter file name: ");
  612.   scanz("%s",fname);
  613.   if (fname[0] == '\0') strcpy(fname,"chess.000");
  614.   if ((fd = fopen(fname,"r")) != NULL)
  615.     {
  616.       fscanf(fd,"%hd%hd%hd",&computer,&opponent,&Game50);
  617.       fscanf(fd,"%hd%hd%hd%hd",
  618.              &castld[white],&castld[black],
  619.              &kingmoved[white],&kingmoved[black]);
  620.       fscanf(fd,"%hd%hd",&TCflag,&OperatorTime);
  621.       fscanf(fd,"%ld%ld%hd%hd",
  622.              &TimeControl.clock[white],&TimeControl.clock[black],
  623.              &TimeControl.moves[white],&TimeControl.moves[black]);
  624.       for (sq = 0; sq < 64; sq++)
  625.         {
  626.           fscanf(fd,"%hd",&m);
  627.           board[sq] = (m >> 8); color[sq] = (m & 0xFF);
  628.           if (color[sq] == 0) color[sq] = neutral; else --color[sq];
  629.         }
  630.       GameCnt = -1; c = '?';
  631.       while (c != EOF)
  632.         {
  633.           ++GameCnt;
  634.           c = fscanf(fd,"%hd%hd%hd%ld%hd%hd%hd",&GameList[GameCnt].gmove,
  635.                      &GameList[GameCnt].score,&GameList[GameCnt].depth,
  636.                      &GameList[GameCnt].nodes,&GameList[GameCnt].time,
  637.                      &GameList[GameCnt].piece,&GameList[GameCnt].color);
  638.           if (GameList[GameCnt].color == 0) GameList[GameCnt].color = neutral;
  639.           else --GameList[GameCnt].color;
  640.         }
  641.       GameCnt--;
  642.       if (TimeControl.clock[white] > 0) TCflag = true;
  643.       computer--; opponent--;
  644.     }
  645.   fclose(fd);
  646.   InitializeStats();
  647.   UpdateDisplay(0,0,1,0);
  648.   Sdepth = 0;
  649. }
  650.  
  651.  
  652. SaveGame()
  653. {
  654. FILE *fd;
  655. char fname[40];
  656. short sq,i,c;
  657.  
  658.   printz("Enter file name: ");
  659.   scanz("%s",fname);
  660.   
  661.   if (fname[0] == '\0' || access(fname,W_OK) == -1) strcpy(fname,"chess.000");
  662.   fd = fopen(fname,"w");
  663.   fprintf(fd,"%d %d %d\n",computer+1,opponent+1,Game50);
  664.   fprintf(fd,"%d %d %d %d\n",
  665.           castld[white],castld[black],kingmoved[white],kingmoved[black]);
  666.   fprintf(fd,"%d %d\n",TCflag,OperatorTime);
  667.   fprintf(fd,"%ld %ld %d %d\n",
  668.           TimeControl.clock[white],TimeControl.clock[black],
  669.           TimeControl.moves[white],TimeControl.moves[black]);
  670.   for (sq = 0; sq < 64; sq++)
  671.     {
  672.       if (color[sq] == neutral) c = 0; else c = color[sq]+1;
  673.       fprintf(fd,"%d\n",256*board[sq] + c);
  674.     }
  675.   for (i = 0; i <= GameCnt; i++)
  676.     {
  677.       if (GameList[i].color == neutral) c = 0;
  678.       else c = GameList[i].color + 1;
  679.       fprintf(fd,"%d %d %d %ld %d %d %d\n",
  680.               GameList[i].gmove,GameList[i].score,GameList[i].depth,
  681.               GameList[i].nodes,GameList[i].time,
  682.               GameList[i].piece,c);
  683.     }
  684.   fclose(fd);
  685. }
  686.  
  687.  
  688. ListGame()
  689. {
  690. FILE *fd;
  691. short i,f,t;
  692.   fd = fopen("chess.lst","w");
  693.   fprintf(fd,"\n");
  694.   fprintf(fd,"       score  depth  nodes  time         ");
  695.   fprintf(fd,"       score  depth  nodes  time\n");
  696.   for (i = 0; i <= GameCnt; i++)
  697.     {
  698.       f = GameList[i].gmove>>8; t = (GameList[i].gmove & 0xFF);
  699.       algbr(f,t,false);
  700.       if ((i % 2) == 0) fprintf(fd,"\n"); else fprintf(fd,"         ");
  701.       fprintf(fd,"%5s  %5d     %2d %6ld %5d",mvstr1,
  702.               GameList[i].score,GameList[i].depth,
  703.               GameList[i].nodes,GameList[i].time);
  704.     }
  705.   fprintf(fd,"\n\n");
  706.   fclose(fd);
  707.  
  708.  
  709. Undo()
  710.  
  711. /*
  712.    Undo the most recent half-move.
  713. */
  714.  
  715. {
  716. short f,t;
  717.   f = GameList[GameCnt].gmove>>8;
  718.   t = GameList[GameCnt].gmove & 0xFF;
  719.   if (board[t] == king && distance(t,f) > 1)
  720.     castle(GameList[GameCnt].color,f,t,2);
  721.   else
  722.     {
  723.       board[f] = board[t]; color[f] = color[t];
  724.       board[t] = GameList[GameCnt].piece;
  725.       color[t] = GameList[GameCnt].color;
  726.       if (board[f] == king) --kingmoved[color[f]];
  727.     }
  728.   if (TCflag) ++TimeControl.moves[color[f]];
  729.   GameCnt--; mate = false; Sdepth = 0;
  730.   UpdateDisplay(0,0,1,0);
  731.   InitializeStats();
  732. }
  733.  
  734.  
  735. ShowMessage(s)
  736. char *s;
  737. {
  738. #ifndef CHESSTOOL
  739.   printz("%s\n",s);
  740. #endif CHESSTOOL
  741. }
  742.  
  743. ShowSidetomove()
  744. {
  745. }
  746.  
  747. PromptForMove()
  748. {
  749. #ifndef CHESSTOOL
  750.   printz("\nYour move is? ");
  751. #endif CHESSTOOL
  752. }
  753.  
  754.  
  755. ShowCurrentMove(pnt,f,t)
  756. short pnt,f,t;
  757. {
  758. }
  759.  
  760. ChangeAlphaWindow()
  761. {
  762.   printz("window: ");
  763.   scanz("%hd",&Awindow);
  764. }
  765.  
  766. ChangeBetaWindow()
  767. {
  768.   printz("window: ");
  769.   scanz("%hd",&Bwindow);
  770. }
  771.  
  772. GiveHint()
  773. {
  774.   algbr((short)(hint>>8),(short)(hint & 0xFF),false);
  775.   printz("try %s\n",mvstr1);
  776. }
  777.  
  778.  
  779. SelectLevel()
  780. {
  781.   OperatorTime = 30000;
  782.   printz("Enter #moves #minutes: ");
  783.   scanz("%hd %hd",&TCmoves,&TCminutes);
  784.   printz("Operator time= ");
  785.   scanz("%hd",&OperatorTime);
  786.   TCflag = (TCmoves > 1);
  787.   SetTimeControl();
  788. }
  789.  
  790.  
  791. ChangeSearchDepth()
  792. {
  793.   printz("depth= ");
  794.   scanz("%hd",&MaxSearchDepth);
  795. }
  796.  
  797. SetContempt()
  798. {
  799.   printz("contempt= ");
  800.   scanz("%hd",&contempt);
  801. }
  802.  
  803. ChangeXwindow()
  804. {
  805.   printz("xwndw= ");
  806.   scanz("%hd",&xwndw);
  807. }
  808.